const jtw = require('jsonwebtoken');
const { PRIVATE_KEY } = require('../app/config');

class AuthController {
  async login(ctx, next) {
    
    const { id, name, avatar_url } = ctx.user;
    const token = jtw.sign({ id, name }, PRIVATE_KEY, {
      expiresIn: 60 * 60 * 24,
      algorithm: 'RS256',
    });
    ctx.body = {
      data: {
        id,
        name,
        token,
        avatar_url,
      },
      success: true,
    };
  }

  async success(ctx, next) {
    ctx.body = '授权成功';
  }
}

module.exports = new AuthController();
